package com.hmall.item.service.impl;

import com.hmall.category.pojo.Category;
import com.hmall.item.mapper.CategoryMapper;
import com.hmall.item.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * (Category)表服务实现类
 *
 * @author makejava
 * @since 2024-06-29 15:08:37
 */
@Service("CategoryService")
public class CategoryServiceImpl implements CategoryService {
    @Autowired
    CategoryMapper categoryMapper;

    /**
     * 分页查询
     *
     * @param page 页码
     * @param size 每页大小
     * @return 查询结果
     */
    @Override
    public List<Category> queryByPage(int page, int size) {
        int start = (page - 1) * size;
        return categoryMapper.queryByPage(start, size);
    }

    /**
     * 新增数据
     *
     * @param category 实例对象
     * @return 实例对象
     */
    @Override
    public void addCategory(Category category) {
        categoryMapper.insert(category);
    }

    /**
     * 修改数据
     *
     * @param category 实例对象
     * @return 实例对象
     */
    @Override
    public void update(Category category) {
        categoryMapper.update(category);
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public int deleteById(Long id) {
        return categoryMapper.deleteById(id);
    }

    @Override
    public long getTotal() {
        return categoryMapper.count();
    }
}
